import { getAllServiceMessage, } from '@/request/api/wechatTweet'

export function usePublicCompo() {
  function getDiaAllSelect(fieldList) {
    return new Promise(resolve => {
      let pro = []
      fieldList.forEach(item => {
        let { api, } = item
        if(api) {
          let proItem = api()
          proItem.then(res => {
            if(res.errcode === 0) {
              item.options = res.row
            } 
          })
          pro.push(proItem)
        }
      })

      Promise.all(pro).then(res => {
        resolve()
      })
    })
  }
  function getDetlData(row) {
    let { row_id, } = row
    return new Promise(resolve => {
      getAllServiceMessage({
        row_id,
      }).then(res => {
        if(res.errcode !== 0) return
        let { row, } = res
        
        if(row[0]) {
          let { members, } = row[0]
          members = members?.split(',') || []
          row[0].members = members
        }

        resolve(row[0])
      })
    })
  }

  return {
    getDiaAllSelect,
    getDetlData,
  }
}